package com.lsk.wxa;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.lsk.admin.shop.ShopServices;

import java.util.ArrayList;
import java.util.List;

public class WxaService {
    static ShopServices shopServices=new ShopServices();
    //根据id查询商品详情
    public Record findTicketdetail(String id){
        String sql="SELECT * FROM ticket WHERE id='"+id+"'";
        Record record= Db.findFirst(sql);
        String sku=record.get("ticketSku");
        Gson gson2=new Gson();
        List<Record> skuList = gson2.fromJson(sku, new TypeToken<List<Record>>() {}.getType());
        record.set("sku",skuList);
        String lunboSql="SELECT a.* FROM shop_commodity_imgpath a WHERE commodityId='"+id+"'";//轮播图
        List<Record> lunboList=Db.find(lunboSql);
        record.set("lunbo",lunboList);
        //查询人员类型
        List<Record> peopleTypeList=this.findAllticketTypeBysysId("ticket_person_type", (String) record.get("shopId"));//人员类型
        List<Record> ticket_typeList=this.findAllticketTypeBysysId("ticket_type",(String) record.get("shopId"));//票种
        List<Record> ticket_methodList=this.findAllticketTypeBysysId("ticket_method",(String) record.get("shopId")); //取表方式
        record.set("peopleTypeList",peopleTypeList);
        record.set("ticket_typeList",ticket_typeList);
        record.set("ticket_methodList",ticket_methodList);
        return  record;
    }

    //根据表名,sys_userId 查询商品对应分类集合
    public List<Record> findAllticketTypeBysysId(String tableName,String shopId){
        String sql="  SELECT a.* FROM  "+tableName+" a  JOIN   shop b ON  a.shopId=b.id WHERE b.id='"+shopId+"'";
        List<Record> list=new ArrayList<>();
        try {
            list=Db.find(sql);
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }
}
